//
//  MenusCell.m
//  Menu
//
//  Created by mc on 16/4/15.
//  Copyright © 2016年 xmj. All rights reserved.
//

#import "MenusCell.h"
#import "Menus.h"
#import <UIImageView+WebCache.h>
#import "View+MASAdditions.h"

/** 标题字体 */
#define kNameFont   [UIFont systemFontOfSize:16]
/** 正文字体 */
#define kTextFont   [UIFont systemFontOfSize:14]
@interface MenusCell()
@property (nonatomic, strong) UIImageView *pictureView;
@property (nonatomic, strong) UILabel *titleView;
@property (nonatomic, strong) UILabel *textView;

@end

@implementation MenusCell

- (UILabel *)textView{
    if (_textView ==nil) {
        _textView = [[UILabel alloc]init];
        _textView.font = kTextFont;
        _textView.numberOfLines = 0;
        [self.contentView addSubview:_textView];
    }
    return _textView;
}

- (UIImageView *)pictureView{
    if (_pictureView ==nil) {
        _pictureView = [[UIImageView alloc]init];
        [self.contentView addSubview:_pictureView];
    }
    return _pictureView;
}

- (UILabel *)titleView{
    if (_titleView ==nil) {
        _titleView = [[UILabel alloc]init];
        _titleView.font = kNameFont;
        [self.contentView addSubview:_titleView];
    }
    return _titleView;
}
- (void)setMenus:(Menus *)menus
{
    _menus = menus;
    
    // 1> 设置数据
    [self settingData];
    
    // 2> 设置位置
    [self settingFrame];
}

- (void)settingData
{
    
    // 正文
    self.textView.text = self.menus.intro;
    [self.pictureView sd_setImageWithURL:[NSURL URLWithString:self.menus.albums]];
    self.titleView.text = self.menus.title;
  
}
- (void)settingFrame
{
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.height.equalTo(@180);
        make.bottom.equalTo(self.titleView.mas_top).with.offset(3);
        
    }];
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
       // make.top.equalTo(self.pictureView.mas_bottom);
        make.height.equalTo(@30);
    }];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
       // make.height.equalTo(@70);
        make.top.equalTo(self.titleView.mas_bottom).with.offset(3);
    }];
    self.cellHeight = CGRectGetMaxY(self.textView.frame);
}

+ (instancetype)menusCellWithTableView:(UITableView *)tableView
 {
     static NSString *ID = @"menusCell";
     MenusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
     if (cell == nil) {
        cell = [[MenusCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
     }
    return cell;
 }


@end
